<?php
// settings include
include ("../config.php");

//page def
//the page title
$title = "Delete Recipe";

// dB connection
include ("$install_dir/include/db.php");

//adds the header
include ("$install_dir/include/head.php");

//start page
?>
<body>
<center>
<table class="main_table">
<tr>
<th colspan="2" class="logo"><img src="<?php echo $install_url;?>/images/logo.png" alt="My Personal Cookbook" align="left" /></th>
</tr>
<tr>
<td class="menu">
<?php
//adds menu
include ("$install_dir/include/menu.php");

?>
</td>
<td class="page">
<div class = "title">:. <?php echo $title;?> .:</div>
<div class = "post_text">
<?php
if ($mode == NULL && $rec_id == NULL) {
   echo "Error no rec_id!";
   echo "Error no mode!";
}

elseif ($mode == "list") {
	 echo "<b>Select a catigory...</b><br />\n<br />\n";
	 $query = "SELECT * FROM recipe GROUP BY rec_cat ASC";
   	 $result = mysql_query($query) or die(mysql_error());
	 while ($row = mysql_fetch_array($result)) {
	 echo "<a href=\"$install_url/admin/del.php?mode=listcat&rec_cat=$row[rec_cat]\">$row[rec_cat]</a><br />\n";
	 }
	 echo "<br />\n<b><a href=\"$install_url/admin/del.php?mode=listall\">List All</a></b><br />\n<b><a href=\"$install_url/admin/index.php\">Back to admin index.</a></b><br />\n";
}

elseif ($mode == "listcat") {
	 echo "<b>Select a recipe...</b><br />\n<br />\n";
	 $query = "SELECT * FROM recipe WHERE rec_cat='$rec_cat' ASC";
   	 $result = mysql_query($query) or die(mysql_error());
	 while ($row = mysql_fetch_array($result)) {
	 echo "<a href=\"$install_url/admin/del.php?rec_id=$row[rec_id]\">$row[rec_name]</a><br />\n";
	 }
	 echo "<br />\n<b><a href=\"$install_url/admin/del.php?mode=listall\">List All</a></b><br />\n<b><a href=\"$install_url/admin/del.php?mode=list\">Back to list of catigories.</a></b><br />\n";
}

elseif ($mode == "listall") {
	 echo "<b>Select a recipe...</b><br />\n<br />\n";
	 $query = "SELECT * FROM recipe GROUP BY rec_name ASC";
   	 $result = mysql_query($query) or die(mysql_error());
	 while ($row = mysql_fetch_array($result)) {
	 echo "<a href=\"$install_url/admin/del.php?rec_id=$row[rec_id]\">$row[rec_name]</a><br />\n";
	 }
	 echo "<br />\n<b><a href=\"$install_url/admin/del.php?mode=list\">Back to list of catigories.</a></b><br />\n";
}

elseif ($mode == NULL && $rec_id != NULL) {
	   ?>
	   <b>Are you sure you wont to Delete this recipe?</b><br />
	   <form method="POST" action="<?php echo $install_url;?>/admin/del.php?mode=yes&rec_id=<?php echo $rec_id;/**/?>">
	   <input type="submit" value="Yes!"><!--<input type="hidden" name="mode" value="yes" /><input type="submit" name="confirm" value="Yes" />&nbsp;<input type="hidden" name="mode" value="no" /><input type="submit" name="cancel" value="No" class="liteoption" />-->
	   </form>
	   <form method="POST" action="<?php echo $install_url;?>/admin/del.php?mode=no&rec_id=<?php echo $rec_id;?>">
	   <input type="submit" value="No!">
	   </form><!---->
	   <?php
}
elseif ($mode == "yes" && $rec_id != NULL) {
	   $query = "DELETE FROM recipe WHERE rec_id=$rec_id";
   	   $result = mysql_query($query) or die(mysql_error());
	   ?>
		 Deleting recipe from dB, <a href="<?php echo $install_url;?>/admin/index.php">Back to Admin Home</a>
		 <script language="Javascript">
		 <!--
		 var URL = "./";
		 var speed = '0';
		 function reload() {
		 location = URL;
		 }
		 setTimeout("reload()", speed);
		 //-->
		 </script>
	   <?php
}
elseif ($mode == "no" && $rec_id != NULL) {
	   ?>
		 Nothing done to recipe, <a href="<?php echo $install_url;?>/admin/index.php">Back to Admin Home</a>
		 <script language="Javascript">
		 <!--
		 var URL = "./";
		 var speed = '0';
		 function reload() {
		 location = URL;
		 }
		 setTimeout("reload()", speed);
		 //-->
		 </script>
	   <?php
}
else {
	 echo "Error unknown mode!";
}
?>
</div>
</td>
</tr>
<tr>
<td colspan="2" class="foot">
<?php
//adds footer
include ("$install_dir/include/footer.php");

?>
</td>
</tr>
</table>
</center>
</body>
</html>